package com.imagination.applet.domain.photo.model;

import com.imagination.applet.domain.adapter.OSSConfiguration;
import com.imagination.applet.domain.common.entity.AbstractEntity;
import com.imagination.applet.domain.utils.OssUtil;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

@SuperBuilder
@Entity
@Table(name = "t_user_photos")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class UserPhoto extends AbstractEntity {
    public static final String PREFIX_PATH = "photos/";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "user_id")
    private Long userId;

    @Enumerated(value = EnumType.STRING)
    @Column(name = "photo_type")
    private PhotoType photoType;

    @Column(name = "photo_path")
    private String photoPath;

    @Column(name = "available")
    private Boolean available;

    @Column(name = "deleted", insertable = false)
    private Boolean deleted;

    @Column(name = "type")
    private Integer type;

    public String getPath() {
        return PREFIX_PATH + photoPath;
    }

    public String getLink() {
        return OssUtil.getTempUrl(photoPath);
    }
}
